﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace Reggie.UI.ViewModels
{
    /// <summary>
    /// The view model responsible for the "shell" of the application, including menu commands
    /// </summary>
    public class MainWindowViewModel : ClosableViewModel
    {
        #region Constants

        private const string ReggieHomePage = "http://reggie.codeplex.com";

        #endregion

        /// <summary>
        /// Initializes a new instance of the <see cref="MainWindowViewModel"/> class.
        /// </summary>
        public MainWindowViewModel()
        {
            this.DisplayName = "Reggie - Regular Expression Generator/Tester";
        }

        #region Menu Commands

        // Creating a private variable so that the command will be lazy-loaded but then cached for future use
        private ICommand m_homePageLinkCommand;

        public ICommand HomepageLinkCommand
        {
            get
            {
                if (m_homePageLinkCommand == null)
                {
                    m_homePageLinkCommand = new RelayCommand(x => System.Diagnostics.Process.Start(ReggieHomePage));
                }
                return m_homePageLinkCommand;
            }
        }

        private ICommand m_aboutCommand;

        /// <summary>
        /// Returns the command that, when invoked, attempts
        /// to remove this workspace from the user interface.
        /// </summary>
        public ICommand AboutCommand
        {
            get
            {
                if (m_aboutCommand == null)
                {
                    m_aboutCommand = new RelayCommand(param => this.OnAboutOpen());
                }

                return m_aboutCommand;
            }
        }

        public event EventHandler AboutOpen;

        private void OnAboutOpen()
        {
            EventHandler handler = this.AboutOpen;
            if (handler != null)
            {
                handler(this, EventArgs.Empty);
            }
        }

        #endregion
    }
}
